package com.qlk.vorder.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qlk.vorder.domain.OrderNote;
import com.qlk.vorder.domain.query.OrderNoteQuery;
import com.qlk.vorder.manager.OrderNoteManager;
import com.qlk.vorder.service.OrderNoteService;
import com.qlk.vorder.utils.exceptions.ExistedException;
import com.qlk.common.utils.page.PageUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.perf4j.aop.Profiled;

/**
 * OrderNoteService接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-7-28 14:14:00
 * 
 */
@Service
public class OrderNoteServiceImpl implements OrderNoteService {

	/** LOG */
	private static final Log LOG = LogFactory.getLog(OrderNoteServiceImpl.class);

	@Autowired
	private OrderNoteManager orderNoteManager;

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "OrderNoteService.batchInsert")
	public boolean insert(List<OrderNote> orderNoteList) {
		boolean resultFlag = false;
		try {
			if (CollectionUtils.isNotEmpty(orderNoteList)) {
				resultFlag = orderNoteManager.insert(orderNoteList);
			} else {
				LOG.warn("OrderNoteServiceImpl#batchInsert failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("OrderNoteServiceImpl#batchInsert has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "OrderNoteService.insert")
	public boolean insert(OrderNote orderNote) {
		boolean resultFlag = false;
		try {
			if (null != orderNote) {
				resultFlag = orderNoteManager.insert(orderNote);
			} else {
				LOG.warn("OrderNoteServiceImpl#insert failed, param is illegal.");
			}
		} catch (ExistedException e) {
			LOG.warn("OrderNoteServiceImpl#insert failed, orderNote has existed.");
			throw e;
		} catch (Exception e) {
			LOG.error("OrderNoteServiceImpl#insert has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "OrderNoteService.update")
	public boolean update(OrderNote orderNote) {
		boolean resultFlag = false;
		try {
			if (null != orderNote && null != orderNote.getId()) {
				resultFlag = orderNoteManager.update(orderNote);
			} else {
				LOG.warn("OrderNoteServiceImpl#update failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("OrderNoteServiceImpl#update has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "OrderNoteService.queryOrderNoteList")
	public List<OrderNote> queryOrderNoteList(OrderNoteQuery queryBean) {
		List<OrderNote> orderNoteList = null;
		try {
			orderNoteList = orderNoteManager.queryOrderNoteList(queryBean);
		} catch (Exception e) {
			LOG.error("OrderNoteServiceImpl#queryOrderNoteList has error.", e);
		}
		return orderNoteList;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "OrderNoteService.queryOrderNoteListWithPage")
	public List<OrderNote> queryOrderNoteListWithPage(OrderNoteQuery queryBean, PageUtil pageUtil) {
		List<OrderNote> orderNoteList = null;
		try {
			orderNoteList = orderNoteManager.queryOrderNoteListWithPage(queryBean, pageUtil);
		} catch (Exception e) {
			LOG.error("OrderNoteServiceImpl#queryOrderNoteListWithPage has error.", e);
		}
		return orderNoteList;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "OrderNoteService.delete")
	public boolean delete(OrderNote orderNote) {
		boolean resultFlag = false;
		try {
			if (null != orderNote && null != orderNote.getId()) {
				resultFlag = orderNoteManager.delete(orderNote);
			} else {
				LOG.warn("OrderNoteServiceImpl#delete param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("OrderNoteServiceImpl#delete has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "OrderNoteService.batchDelete")
	public boolean delete(OrderNote[] orderNotes) {
		boolean resultFlag = false;
		try {
			if (null != orderNotes && orderNotes.length > 0) {
				resultFlag = orderNoteManager.delete(orderNotes);
			} else {
				LOG.warn("OrderNoteServiceImpl#batchDelete failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("OrderNoteServiceImpl#batchDelete has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "OrderNoteService.getOrderNoteById")
	public OrderNote getOrderNoteById(Long id) {
		OrderNote orderNote = null;
		try {
			if (null != id) {
				orderNote = orderNoteManager.getOrderNoteById(id);
			} else {
				LOG.warn("OrderNoteServiceImpl#getOrderNoteById failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("OrderNoteServiceImpl#getOrderNoteById has error.", e);
		}
		return orderNote;
	}
}
